<?php

/**
 * @author 
 * @copyright 2012
 */

defined( '_JEXEC' ) or die( 'Restricted access' ); 

class GSTools {

		var $_params_cookie = array();

		var $template = '';

		

		function GSTools ($template, $_params_cookie=null) {

			$this->_tpl = $template;

			$template->_tools = $this;

			$this->template = $template->template;

			

			if(!$_params_cookie) {

				$this->_params_cookie = $this->_tpl->params->toArray();

			} else {

				foreach ($_params_cookie as $k) {

					$this->_params_cookie[$k] = $this->_tpl->params->get($k);

				}

			}			

	

			$this->getUserSetting();

		}

	

		function getUserSetting(){

			$exp = time() + 60*60*24*355;

			if (isset($_COOKIE[$this->template.'_tpl']) && $_COOKIE[$this->template.'_tpl'] == $this->template){

				foreach($this->_params_cookie as $k=>$v) {

					$kc = $this->template."_".$k;

					if (JRequest::getVar($k, null, 'GET') !== null) {

						$v = preg_replace('/[\x00-\x1F\x7F;\"\'%()]/', '', JRequest::getString($k, '', 'GET'));

						setcookie ($kc, $v, $exp, '/');

					}else{

						if (isset($_COOKIE[$kc])){

							$v = $_COOKIE[$kc];

						}

					}

					$this->setParam($k, $v);

				}

	

			}else{

				setcookie ($this->template.'_tpl', $this->template, $exp, '/');

			}

			return $this;

		}
        function genHeader(){

			$doc =& JFActory::getDocument();

			$doc->addStyleSheet("templates/".$this->template."/css/template.css");
            
            $doc->addStyleSheet("templates/".$this->template."/css/horizontal-menumatic.css");
            
            $doc->addStyleSheet("templates/".$this->template."/css/vertical-menumatic.css");
            
            $doc->addStyleSheet("templates/".$this->template."/css/besps.css");

			$doc->addScript("templates/".$this->template."/js/jquery.js");
			

		}
}
?>